package com.woniuxy.bookmall.controller;

import com.woniuxy.bookmall.entity.TBanner;
import com.woniuxy.bookmall.entity.TBooktype;
import com.woniuxy.bookmall.service.BannerService;
import com.woniuxy.bookmall.service.BookService;
import com.woniuxy.bookmall.service.BookTypeService;
import com.woniuxy.bookmall.service.EsService;
import com.woniuxy.bookmall.vo.EsBook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用于查询首页数据
 */
@Controller
public class IndexController {
    @Autowired
    BookTypeService bookTypeService ;
    @Autowired
    BannerService bannerService ;
    @Autowired
    BookService bookService ;

    @Autowired
    EsService esService ;

    @RequestMapping("/book/index")
    public String indexPage(Map map){ //map 操作的是 reqeust作用域
        //1.查询  图书分类
        List<TBooktype> typeList = bookTypeService.findAll();
        //2.查询  轮播图
        List<TBanner> bannerList = bannerService.findAll();
        //3.查询 热卖图书
        List<EsBook> hotList = esService.findEsBookByType(0, 8);
        //4 .查询 新书
        List<EsBook> newList = esService.findEsBookByType(1, 8);
        //5  查询 收藏最多的图书
        List<EsBook> colList = esService.findEsBookByType(2, 8);

        map.put("typeList",typeList);
        map.put("bannerList",bannerList);
        map.put("hotList",hotList);
        map.put("newList",newList);
        map.put("colList",colList);

        return  "index"; //转发到 idnex.html
    }
}
